Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix whisper compile #35413

Merged
merged 3 commits into from
Jan 13, 2025
Merged

Fix whisper compile #35413

merged 3 commits into from
Jan 13, 2025

Conversation

jiqing-feng
Copy link
Contributor

@jiqing-feng jiqing-feng commented Dec 25, 2024

This change could fix the whisper compile error.
Besides, we don't need cache here, this change also avoids the log warning [here].

To reproduce the error:

import torch
from transformers import pipeline
from datasets import load_dataset

pipe = pipeline("automatic-speech-recognition", model="openai/whisper-small")
pipe.model.forward = torch.compile(pipe.model.forward)
ds = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
sample = ds[0]["audio"]
prediction = pipe(sample.copy(), batch_size=8)["text"]
print(prediction)

Traceback:

...
    if truth_fn(mod):
  File "/home/jiqing/transformers/src/transformers/cache_utils.py", line 405, in __len__
    return len(self.key_cache)
  File "/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py", line 1931, in __getattr__
    raise AttributeError(
torch._dynamo.exc.InternalTorchDynamoError: AttributeError: 'DynamicCache' object has no attribute 'key_cache'

Require test?

Signed-off-by: jiqing-feng <[email protected]>
@jiqing-feng jiqing-feng changed the title Fix whisper compile error Fix whisper warning Dec 25, 2024
@jiqing-feng jiqing-feng changed the title Fix whisper warning Fix whisper compile Dec 25, 2024
@LysandreJik
Copy link
Member

cc @eustlb

@jiqing-feng
Copy link
Contributor Author

Hi @LysandreJik @eustlb please let me know where can I add the test. Thanks!

@jiqing-feng
Copy link
Contributor Author

Waiting for review ...

Copy link
Collaborator

@ArthurZucker ArthurZucker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep sorry that you did not get a review earlier! 🤗 we indeed do'n need cache when computing logits as you are not re-using the cache. An improvement would be to actually output the cache in this case, to re=use it rather than re-runing a forward pass probably!

@ArthurZucker ArthurZucker merged commit b8c34d9 into huggingface:main Jan 13, 2025
14 checks passed
@jiqing-feng jiqing-feng deleted the whisper branch January 17, 2025 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants